import React, { useEffect, useState } from 'react'

export default function () {
        const [windowSize, setWindowSize] = useState(window.innerWidth);

        let time : any = null
        const handleResize = () => {
            if(time !== null){
                clearTimeout(time)
            }
            time = setTimeout (()=>{
                setWindowSize(window.innerWidth);
            },500)
        };
    
        useEffect(() => {
            // 监听
            window.addEventListener('resize', handleResize);
            
            // 销毁
            return () => window.removeEventListener('resize', handleResize)
        }, []);
    
        return windowSize;
}

